package com.appspot.didit.client.workitem;

import java.io.Serializable;
import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "false")
public class Workitem implements Serializable{
	
	private static final long serialVersionUID = -1609410717417616727L;
	
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	protected Long id;
	@Persistent
	protected String description;
	
	@Persistent
	protected double duration;
	
	@Persistent
	protected String tagString;
	
	@Persistent
	protected Date date;
	
	@Persistent
	protected Long user_id;
	
	@Persistent
	protected Date created;
	

	public Workitem() {	
	}
	/*
	public Workitem(String description, ArrayList<Tag> tags, int dauer) {
		this.description = description;
		this.tags = tags;
		this.duration = dauer;
		this.date = new Date();
	}
	
	

	public Workitem(String description, String tagString, int dauer, Long user_id) {
		this.description = description;
		this.tagString = tagString;
		this.duration = dauer;
		this.user_id = user_id;
		this.date = new Date();
	}

	public Workitem(String description, int dauer) {
		this.description = description;
		this.duration = dauer;
		this.tags = new ArrayList<Tag>();
		this.date = new Date();
	}
	
	public Workitem(String description, int dauer, Long user_id) {
		this.description = description;
		this.duration = dauer;
		this.tags = new ArrayList<Tag>();
		this.user_id = user_id;
		this.date = new Date();
	}
	
	public Workitem(String description, int dauer, String tagString, Long user_id) {
		this.description = description;
		this.duration = dauer;
		this.tagString = tagString;
		this.tags = new ArrayList<Tag>();
		this.user_id = user_id;
		this.date = new Date();
	}
	public Workitem(String description, int dauer, String tagString, Long user_id) {
		this.description = description;
		this.duration = dauer;
		this.tagString = tagString;
		this.tags = new ArrayList<Tag>();
		this.user_id = user_id;
		this.date = new Date();
	}
		@NotPersistent
	protected ArrayList<Tag> tags;
	
	public ArrayList<Tag> getTags() {
		return tags;
	}

	public void setTags(ArrayList<Tag> tags) {
		this.tags = tags;
	}
		
	public void addTag(Tag tag) {
		this.tags.add(tag);
	}
	
	public void delTag(Tag tag) {
		for(Tag t : tags) {
			if(tag.equals(t)) {
				tags.remove(t);
			}
		}
	}
	*/
	
	public Workitem(String description, double duration, String tagString, Date date, Long user_id) {
		this.description = description;
		this.duration = duration;
		this.tagString = tagString;
		this.user_id = user_id;
		this.date = date;
		this.created = new Date();
	}
	
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public double getDuration() {
		return duration;
	}

	public void setDuration(double duration) {
		this.duration = duration;
	}

	public Long getUser_id() {
		return user_id;
	}

	public void setUser_id(Long user_id) {
		this.user_id = user_id;
	}
	


	public String getTagString() {
		return tagString;
	}

	public void setTagString(String tagString) {
		this.tagString = tagString;
	}
	
	public void update(Workitem wi) {
		this.description = wi.getDescription();
		this.duration = wi.getDuration();
		this.tagString = wi.getTagString();
		this.date = wi.getDate();
		this.created = wi.getCreated();
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}
	
	public String toString() {
		return "Workitem id:"+this.id + ", beschreibung:"+this.description+", Projekte:"+this.getTagString()+", duration:"+this.getDuration()+", date:"+this.getDate()+", User:"+this.user_id;
	}
}

